home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Applications / DropBin 1.5 / DropBin.p < prev    next >
Text File  |  1997-05-20  |  5KB  |  196 lines

  1. {******************************************************************************
  2. //
  3. //  DropBin v1.5
  4. //
  5. //  This program encodes a binhex file.  Either drop a file on this application,
  6. //  or open a file from within this app, and it will binhex the file.
  7. //
  8. //  This program started as a port of a C program by Matthew Mora called AutoBin.
  9. //  The CalcCRC stuff was replaced with a new routine created from scratch (using
  10. //  the write-up on Binhex 4.0 that Peter N Lewis released).  Some other stuff was
  11. //  also added to improve the user interface (better event handling, progress bar, etc.).
  12. //
  13. // 
  14. //  Programmed by Bill Catambay, 5/20/97.  E-mail at bill@catambay.com
  15. //
  16. ******************************************************************************}
  17. {!$pragma noreturn on}
  18. {$NR+}
  19.  
  20. Program DropBin;
  21.  
  22. Uses
  23.     Toolbox, DropBinUtils, DropBinAE, BinProgress;
  24.     
  25. Procedure InitGlobals;
  26.  
  27. Var
  28.     aLong:    longint;
  29.     
  30.     begin
  31.     gDone := false;
  32.     gBackground := false;
  33.     gState := false;
  34.     gProcessing := false;
  35.     gOApped := false;    
  36.     gHasAppleEvents    := Gestalt(gestaltAppleEventsAttr,aLong) = noErr;
  37.     dbWindow := NIL;
  38.     gRefNum := 0;
  39.     gFilename := '';
  40.     gOutputName := '';
  41.     gStatType := kShowRemaining;
  42.     end;
  43.  
  44. Procedure SetUpMenus;
  45.  
  46.     begin
  47.     gAppleMenu := GetMenu ( kAppleNum );
  48.     AppendResMenu(gAppleMenu, 'DRVR' );
  49.     InsertMenu(gAppleMenu, 0 );
  50.     gFileMenu := GetMenu(kFileNum);
  51.     InsertMenu(gFileMenu, 0);
  52.     DrawMenuBar;
  53.     end;
  54.  
  55. Procedure StartEncode;
  56.  
  57. Var
  58.     stdReply:        StandardFileReply;
  59.  
  60.     begin
  61.     StandardGetFile(NIL, -1, NIL, stdReply);
  62.     if stdReply.sfGood then
  63.         SendODOCToSelf(stdReply.sfFile);
  64.     end;
  65.     
  66. Procedure DoMenu(retVal: longint);
  67.  
  68. Var
  69.     menuID, itemID:    integer;
  70.     itemStr:        Str255;
  71.  
  72.     begin
  73.     menuID := HiWord(retVal);
  74.     itemID := LoWord(retVal);
  75.     case menuID of
  76.         kAppleNum:    if itemID = 1 then
  77.                         Alert(128, NIL)
  78.                     else
  79.                         begin
  80.                         GetMenuItemText(GetMenuHandle(kAppleNum), itemID, itemStr);
  81.                         OpenDeskAcc(itemStr);
  82.                         end;
  83.         kFileNum:    if itemID = 1 then
  84.                         begin
  85.                         HiliteControl(encodeButton, 1);
  86.                         Wait(5);
  87.                         HiliteControl(encodeButton, 0);
  88.                         StartEncode;
  89.                         end
  90.                     else
  91.                         begin
  92.                         HiliteControl(quitButton, 1);
  93.                         SendQuitToSelf;    { send self a 'quit' event }
  94.                         end;
  95.         otherwise    ;
  96.         end; { of CASE }
  97.     HiliteMenu(0);        { turn it off! }
  98.     end;
  99.  
  100. Procedure DoMouseDown(curEvent: EventRecord);
  101.  
  102. Var
  103.     whichWindow:    WindowPtr;
  104.     whichPart:        integer;
  105.     control:         ControlRef;
  106.  
  107.     begin
  108.     whichPart := FindWindow(curEvent.where, whichWindow);
  109.     case whichPart of
  110.         inMenuBar:        DoMenu(MenuSelect(curEvent.where));
  111.         inContent:        if whichWindow = dbWindow then
  112.                             begin
  113.                             SetPort(dbWindow);
  114.                             GlobalToLocal(curEvent.where);
  115.                             if FindControl(curEvent.where, dbWindow, control) > 0 then
  116.                                 if TrackControl(control, curEvent.where, nil) > 0 then
  117.                                     begin
  118.                                     if control = quitButton then
  119.                                         SendQuitToSelf;
  120.                                     if control = encodeButton then
  121.                                         StartEncode;
  122.                                     end;
  123.                             end;
  124.         inSysWindow:    SystemClick(curEvent, whichWindow);
  125.         inDrag:            DragWindow(whichWindow, curEvent.where, qd.screenBits.bounds);
  126.         otherwise    ;
  127.         end; { of CASE }
  128.     end;
  129.  
  130. Procedure DoKeyDown(curEvent: EventRecord);
  131.  
  132. Var
  133.     keyCode:    integer;
  134.     
  135.     begin
  136.     keyCode := BAnd(curEvent.message, charCodeMask);
  137.     if (keyCode = kReturnKey) or (keyCode = kEnterKey) then
  138.         begin
  139.         HiliteControl(encodeButton, 1);
  140.         Wait(5);
  141.         HiliteControl(encodeButton, 0);
  142.         StartEncode;
  143.         end
  144.     else if BAnd(curEvent.modifiers,cmdKey) <> 0 then
  145.         DoMenu(MenuKey(chr(keyCode)));
  146.     end;
  147.  
  148. begin
  149. InitToolbox;
  150. InitGlobals;
  151. if not gHasAppleEvents then
  152.     ErrorAlert(kErrStringID, kCantRunErr, 0)
  153. else 
  154.     begin
  155.     InitAEVTStuff;
  156.     SetUpMenus;
  157.     while not gDone do
  158.         begin
  159.         gWasEvent := WaitNextEvent(everyEvent, gEvent, 60, NIL);
  160.         if gWasEvent then
  161.             case gEvent.what of
  162.                 kHighLevelEvent:    DoHighLevelEvent(gEvent);
  163.                 osEvt:                if BAnd(brotl(gEvent.message,8),$FF) = suspendResumeMessage then
  164.                                         begin
  165.                                         gBackground := BAnd(gEvent.message,resumeFlag) = 0;
  166.                                         if gBackground then
  167.                                             begin
  168.                                             HiliteControl(encodeButton, 255);
  169.                                             HiliteControl(quitButton, 255);
  170.                                             MakeDefaultButton(encodeButton);
  171.                                             end
  172.                                         else
  173.                                             begin
  174.                                             HiliteControl(encodeButton, 0);
  175.                                             HiliteControl(quitButton, 0);
  176.                                             MakeDefaultButton(encodeButton);
  177.                                             end;
  178.                                         InvalRect(WindowPtr(gEvent.message)^.portRect);
  179.                                         end;
  180.                 updateEvt:            begin
  181.                                     InvalRect(WindowPtr(gEvent.message)^.portRect);
  182.                                     ResetWindow(WindowPtr(gEvent.message));
  183.                                     end;
  184.                 mouseDown:            DoMouseDown(gEvent);
  185.                 keyDown,
  186.                 autoKey:            DoKeyDown(gEvent);
  187.                 otherwise            ;
  188.                 end; { of CASE }
  189.         if gState then
  190.             begin
  191.             SetupProgress;
  192.             gState := false;
  193.             end;
  194.         end;
  195.     end;
  196. end.